# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/1/18 14:06
from telnetlib import EC

from selenium.common.exceptions import NoSuchElementException

from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.user_product_computing_locator import ProductComputingLocator
from Case.python_ui.PageLocate.user_product_container_registry_locator import ProductContainerRegistryLocator
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, TimeoutException

import random
import time


class ProductContainerRegistry(Basepage):

    # 根据tab菜单名称进行点击
    def click_my_resource_tab(self, tab_name):
        doc = '根据my resource页的tab菜单名字进行点击进入'
        time.sleep(5)
        self.wait_elevisble(ProductComputingLocator.my_resource_tab_list, doc)
        my_resource_tab_list = self.get_elements(ProductComputingLocator.my_resource_tab_list, doc)
        for i in my_resource_tab_list:
            print('*****:', i.text, type(i))
            if i.text == tab_name:
                print('++++:', i.text)
                i.click()
        time.sleep(2)

    # 根据产品名称进行点击
    def get_product_name_to_click(self, product_name):
        doc = '根据产品名称然后点击'
        prod_list = self.get_elements(ProductComputingLocator.my_resource_product_list, doc)
        time.sleep(2)
        for prod in prod_list:
            print('+++++:', prod.text)
            if prod.text == product_name:
                prod.click()
                break
        time.sleep(5)

    # tab页根据产品名称进行点击进入控制台
    def click_product_by_name(self, product_name):
        doc = 'tab页根据产品名称进行点击进入控制台'
        time.sleep(5)
        self.wait_elevisble(ProductComputingLocator.move_computing_create_new, doc)
        self.move_mouse_to_element(ProductComputingLocator.move_computing_create_new)
        time.sleep(2)
        self.get_product_name_to_click(product_name)
        time.sleep(2)


    # 进入container registry的Acecess Credential页面管理控制页
    def enter_acecess_credential_page(self):
        doc = 'acecess credential页面管理控制页'
        self.click_my_resource_tab('Developer Services')
        self.click_product_by_name('Container Registry')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
                if self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text == 'Repositories':
                    break
            except:
                continue
        self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
        print("iframe++++:",self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        self.wait_elevisble(ProductContainerRegistryLocator.click_access_credential, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_access_credential, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_obtain_credential, doc)
        print('ob:', self.get_element(ProductContainerRegistryLocator.if_obtain_credential, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_obtain_credential, doc).text == 'Obtain Credential'
        self.wait_elevisble(ProductContainerRegistryLocator.if_login_instance, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_login_instance, doc).text == 'Login Instance'
        time.sleep(5)


    # 进入container registry的Acecess Credential页面管理控制页
    def if_acecess_credential_page(self):
        doc = 'acecess credential页面管理控制页'
        self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
        print("iframe++++:",self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        self.wait_elevisble(ProductContainerRegistryLocator.click_access_credential, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_access_credential, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_obtain_credential, doc)
        print('ob:', self.get_element(ProductContainerRegistryLocator.if_obtain_credential, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_obtain_credential, doc).text == 'Obtain Credential'
        self.wait_elevisble(ProductContainerRegistryLocator.if_login_instance, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_login_instance, doc).text == 'Login Instance'
        time.sleep(5)



    def enter_repositories_page(self):
        doc = 'Repositories页面管理控制页'
        self.click_my_resource_tab('Developer Services')
        self.click_product_by_name('Container Registry')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
                if self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text == 'Repositories':
                    break
            except:
                continue
        self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
        print("iframe++++:",self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        self.wait_elevisble(ProductContainerRegistryLocator.if_namespace, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_namespace, doc).text == 'Repository Name'
        self.wait_elevisble(ProductContainerRegistryLocator.if_permissions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_permissions, doc).text == 'Namespace'
        self.wait_elevisble(ProductContainerRegistryLocator.if_status, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_status, doc).text == 'Status'
        self.wait_elevisble(ProductContainerRegistryLocator.if_automatically, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_automatically, doc).text == 'Repository Type'
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository, doc).text == 'Permissions'
        self.wait_elevisble(ProductContainerRegistryLocator.if_actions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_actions, doc).text == 'Repository Address'
        time.sleep(5)

    # #TL635005 | namespace列表
    def enter_namespace_page(self):
        doc = 'namespace列表'
        self.click_my_resource_tab('Developer Services')
        self.click_product_by_name('Container Registry')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
                if self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text == 'Repositories':
                    break
            except:
                continue
        self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
        print("iframe++++:",self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        self.wait_elevisble(ProductContainerRegistryLocator.click_namespace, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_namespace, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.if_namespace, doc)
        print('name_:', self.get_element(ProductContainerRegistryLocator.if_namespace, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_namespace, doc).text == 'Namespace'
        self.wait_elevisble(ProductContainerRegistryLocator.if_permissions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_permissions, doc).text == 'Permissions'
        self.wait_elevisble(ProductContainerRegistryLocator.if_status, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_status, doc).text == 'Status'
        self.wait_elevisble(ProductContainerRegistryLocator.if_automatically, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_automatically, doc).text == 'Automatically Create Repository'
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository, doc).text == 'Default Repository Type'
        self.wait_elevisble(ProductContainerRegistryLocator.if_actions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_actions, doc).text == 'Actions'
        time.sleep(5)

    #复制Repository地址
    def copy_rep_address(self):
        doc = "复制Repository地址"
        self.wait_elevisble(ProductContainerRegistryLocator.click_download_adress, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_download_adress, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_adress, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.if_adress, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.if_copied, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_copied, doc).text == 'Copied'
        time.sleep(5)

    #Repository详情页
    def repository_detail(self):
        doc = "Repository详情页"
        self.wait_elevisble(ProductContainerRegistryLocator.click_repository_name, doc)
        req_status = self.get_element(ProductContainerRegistryLocator.repository_status, doc).text
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_repository_name, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository_name, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository_name, doc).text == 'Repository Name'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_address, doc).text == 'Repository Address'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_region, doc).text == 'Repository Region'
        assert self.get_element(ProductContainerRegistryLocator.if_code_repository, doc).text == 'Code Repository'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_type, doc).text == 'Repository Type'
        assert self.get_element(ProductContainerRegistryLocator.if_summary, doc).text == 'Summary'
        assert self.get_element(ProductContainerRegistryLocator.if_guide, doc).text == 'Guide'
        assert self.get_element(ProductContainerRegistryLocator.if_description, doc).text == 'Description'
        assert self.get_element(ProductContainerRegistryLocator.if_detail_status, doc).text == req_status
        assert self.get_element(ProductContainerRegistryLocator.if_rep_type, doc).text == 'Private' or 'Public'
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_back, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_namespace, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_namespace, doc).text == 'Repository Name'
        self.wait_elevisble(ProductContainerRegistryLocator.if_permissions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_permissions, doc).text == 'Namespace'
        self.wait_elevisble(ProductContainerRegistryLocator.if_status, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_status, doc).text == 'Status'
        self.wait_elevisble(ProductContainerRegistryLocator.if_automatically, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_automatically, doc).text == 'Repository Type'
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository, doc).text == 'Permissions'
        self.wait_elevisble(ProductContainerRegistryLocator.if_actions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_actions, doc).text == 'Repository Address'
        time.sleep(5)

    #Admin repository（查看repository详情）
    def admin_repository_detail(self):
        doc = "Admin repository（查看repository详情）"
        self.wait_elevisble(ProductContainerRegistryLocator.click_admin, doc)
        req_status = self.get_element(ProductContainerRegistryLocator.repository_status, doc).text
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_admin, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository_name, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository_name, doc).text == 'Repository Name'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_address, doc).text == 'Repository Address'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_region, doc).text == 'Repository Region'
        assert self.get_element(ProductContainerRegistryLocator.if_code_repository, doc).text == 'Code Repository'
        assert self.get_element(ProductContainerRegistryLocator.if_repository_type, doc).text == 'Repository Type'
        assert self.get_element(ProductContainerRegistryLocator.if_summary, doc).text == 'Summary'
        assert self.get_element(ProductContainerRegistryLocator.if_guide, doc).text == 'Guide'
        assert self.get_element(ProductContainerRegistryLocator.if_description, doc).text == 'Description'
        assert self.get_element(ProductContainerRegistryLocator.if_detail_status, doc).text == req_status
        assert self.get_element(ProductContainerRegistryLocator.if_rep_type, doc).text == 'Private' or 'Public'
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_back, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_namespace, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_namespace, doc).text == 'Repository Name'
        self.wait_elevisble(ProductContainerRegistryLocator.if_permissions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_permissions, doc).text == 'Namespace'
        self.wait_elevisble(ProductContainerRegistryLocator.if_status, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_status, doc).text == 'Status'
        self.wait_elevisble(ProductContainerRegistryLocator.if_automatically, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_automatically, doc).text == 'Repository Type'
        self.wait_elevisble(ProductContainerRegistryLocator.if_repository, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_repository, doc).text == 'Permissions'
        self.wait_elevisble(ProductContainerRegistryLocator.if_actions, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_actions, doc).text == 'Repository Address'
        time.sleep(5)

    # marketplace列表
    def enter_marketplace_page(self):
        doc = 'marketplace列表'
        self.click_my_resource_tab('Marketplace')
        self.wait_elevisble(ProductContainerRegistryLocator.click_instanceid, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_instanceid, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_basic_info, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_basic_info, doc).text == 'Basic Information'
        assert self.get_element(ProductContainerRegistryLocator.if_app_info, doc).text == 'Application Information'
        assert self.get_element(ProductContainerRegistryLocator.if_product_name, doc).text == 'Product Name'
        assert self.get_element(ProductContainerRegistryLocator.if_product_status, doc).text == 'Status'
        assert self.get_element(ProductContainerRegistryLocator.if_product_detail, doc).text == 'Product Detail'
        assert self.get_element(ProductContainerRegistryLocator.if_created_time, doc).text == 'Created Time'
        assert self.get_element(ProductContainerRegistryLocator.if_front_end_url, doc).text == 'Front End Url'
        assert self.get_element(ProductContainerRegistryLocator.if_admin_url, doc).text == 'Admin Url'
        assert self.get_element(ProductContainerRegistryLocator.if_user_name, doc).text == 'User Name'
        assert self.get_element(ProductContainerRegistryLocator.if_password, doc).text == 'Password'
        assert self.get_element(ProductContainerRegistryLocator.if_authorized_login, doc).text == 'Authorized Login'
        assert self.get_element(ProductContainerRegistryLocator.if_remark, doc).text == 'Remark'
        time.sleep(5)

    #Edit repository setting
    def edit_repository(self):
        doc = "Edit repository setting"
        self.wait_elevisble(ProductContainerRegistryLocator.click_repository_name, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_repository_name, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.edit_rep, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.edit_rep, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.input_summary, doc)
        self.keyboard_event(ProductContainerRegistryLocator.input_summary, doc)
        random_num = random.randint(1, 100000)
        sum = 'test' + str(random_num)
        self.send_keys(ProductContainerRegistryLocator.input_summary, sum, doc)
        time.sleep(5)
        self.keyboard_event(ProductContainerRegistryLocator.input_description, doc)
        random_num = random.randint(1, 100000)
        des = '*good*' + str(random_num)
        des1= 'good'+ str(random_num)
        self.send_keys(ProductContainerRegistryLocator.input_description, des, doc)
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.confirm_repedit, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_description, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.if_description, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.if_summary_value, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_summary_value, doc).text == sum
        assert self.get_element(ProductContainerRegistryLocator.if_description_value, doc).text == des1

    #修改repository type
    def edit_repository_type(self):
        doc = "修改repository type"
        self.wait_elevisble(ProductContainerRegistryLocator.click_repository_name, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_repository_name, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.edit_rep, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.edit_rep, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_private, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_private, doc)
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.confirm_repedit, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_rep_type, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_rep_type, doc).text == 'Private'
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.edit_rep, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.edit_rep, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_public, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_public, doc)
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.confirm_repedit, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_rep_type, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_rep_type, doc).text == 'Public'

    #TL635014 | 修改repository type
    def modify_namespace_repository_type(self):
        doc = '修改repository type'
        self.click_my_resource_tab('Developer Services')
        self.click_product_by_name('Container Registry')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
                if self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text == 'Repositories':
                    break
            except:
                continue
        self.wait_elevisble(ProductContainerRegistryLocator.if_enter_container_registry_page, doc)
        print("iframe++++:",self.get_element(ProductContainerRegistryLocator.if_enter_container_registry_page, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_namespace, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_namespace, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_change_type, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_change_type, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.if_modified, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_modified, doc).text == 'Modified'
        time.sleep(5)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_change_type, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.if_modified, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_modified, doc).text == 'Modified'

    # 进入vpc的route table
    def enter_route_tables_page(self):
        doc = 'route tables页面管理控制页'
        self.click_my_resource_tab('Network')
        self.click_product_by_name('Virtual Private Clouds')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_overview, doc)
                print("if_overview++++:",self.get_element(ProductContainerRegistryLocator.if_overview, doc).text)
                if self.get_element(ProductContainerRegistryLocator.if_overview, doc).text == 'Overview':
                    break
            except:
                continue
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_route_tables, doc)
        print("click_route_tables++++:", self.get_element(ProductContainerRegistryLocator.click_route_tables, doc).text)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_route_tables, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_tag, doc)
        print("if_table_id++++:",self.get_element(ProductContainerRegistryLocator.if_table_id, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_table_id, doc).text == 'Route Table ID/Name'
        print("if_tag++++:",self.get_element(ProductContainerRegistryLocator.if_tag, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_tag, doc).text == 'Tag'
        print("if_vpc_id++++:",self.get_element(ProductContainerRegistryLocator.if_vpc_id, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_vpc_id, doc).text == 'VPC ID/Name'




    # 创建route tables
    def create_route_tables(self):
        doc = 'route tables页面管理控制页'
        self.click_my_resource_tab('Network')
        self.click_product_by_name('Virtual Private Clouds')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_overview, doc)
                print("if_overview++++:",self.get_element(ProductContainerRegistryLocator.if_overview, doc).text)
                if self.get_element(ProductContainerRegistryLocator.if_overview, doc).text == 'Overview':
                    break
            except:
                continue
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_route_tables, doc)
        print("click_route_tables++++:", self.get_element(ProductContainerRegistryLocator.click_route_tables, doc).text)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_route_tables, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_create_route_table, doc)
        print("click_create_route_table++++:",self.get_element(ProductContainerRegistryLocator.click_create_route_table, doc).text)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_create_route_table, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.input_name, doc)
        self.send_keys(ProductContainerRegistryLocator.input_name, 'aaa', doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_submit_button, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_submit_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_ok, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_ok, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_name, doc)
        print("click_create_route_table++++:",self.get_element(ProductContainerRegistryLocator.if_name, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_name, doc).text == 'aaa'
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_delete, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_delete, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_delete_ok, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_delete_ok, doc)


    #进入ecs控制台
    def enter_ecs(self):
        doc='进入ecs'
        self.click_element(ProductContainerRegistryLocator.click_menu_list, doc)
        time.sleep(20)
        self.wait_elevisble(ProductContainerRegistryLocator.click_esc, doc)
        time.sleep(2)
        self.click_element(ProductContainerRegistryLocator.click_esc, doc)
        time.sleep(2)
        self.wait_elevisble(ProductContainerRegistryLocator.iframe_ecs, doc)
        self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_ecs, doc))
        time.sleep(50)

    #进入container_register控制台
    def enter_container_register(self):
        doc='进入container_register控制台'
        self.click_element(ProductContainerRegistryLocator.click_menu_list, doc)
        time.sleep(10)
        self.wait_elevisble(ProductContainerRegistryLocator.input_proname, doc)
        self.send_keys(ProductContainerRegistryLocator.input_proname, 'Container Registry', doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_container_register, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_container_register, doc)
        time.sleep(2)
        self.wait_elevisble(ProductContainerRegistryLocator.iframe_ecs, doc)
        self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_ecs, doc))
        time.sleep(50)



    # 创建安全组
    def create_security_group(self):
        doc = '创建安全组'
        self.wait_elevisble(ProductContainerRegistryLocator.click_security_groups, doc)
        time.sleep(3)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_security_groups, doc)
        time.sleep(20)
        self.wait_elevisble(ProductContainerRegistryLocator.click_create_security_groups, doc)
        time.sleep(3)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_create_security_groups, doc)
        time.sleep(20)
        self.scroll_bar_operation(ProductContainerRegistryLocator.input_security_group_name)
        self.send_keys(ProductContainerRegistryLocator.input_security_group_name, 'aaa', doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_submit_button, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_submit_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_ok, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_ok, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_security_group_name, doc)
        print("click_create_route_table++++:",self.get_element(ProductContainerRegistryLocator.if_security_group_name, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_security_group_name, doc).text == 'aaa'
        time.sleep(5)

     # 删除安全组
    def delete_security_group(self):
        doc = '删除安全组'
        self.wait_elevisble(ProductContainerRegistryLocator.click_delete_security_group, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_delete_security_group, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_ensure_delete, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_ensure_delete, doc)

     # 删除安全组成功
    def delete_security_group_success(self):
        doc = '删除安全组成功'
        self.wait_elevisble(ProductContainerRegistryLocator.if_delete_succ, doc)
        print("click_create_route_table++++:",self.get_element(ProductContainerRegistryLocator.if_delete_succ, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_delete_succ, doc).text == 'Deleted.'

    #修改安全组
    def modify_security_group(self):
        doc = '修改安全组'
        self.wait_elevisble(ProductContainerRegistryLocator.click_modify_security_group, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_modify_security_group, doc)
        time.sleep(10)
        self.wait_elevisble(ProductContainerRegistryLocator.modify_security_group_name, doc)
        self.keyboard_event(ProductContainerRegistryLocator.modify_security_group_name, doc)
        self.send_keys(ProductContainerRegistryLocator.modify_security_group_name, 'bbb', doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.modify_ok, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.modify_ok, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_security_group_name, doc)
        print("modifyname++++:",self.get_element(ProductContainerRegistryLocator.if_security_group_name, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_security_group_name, doc).text == 'bbb'
        time.sleep(5)




    #搜索安全组
    def search_security_group(self):
        doc ='搜索安全组'
        self.wait_elevisble(ProductContainerRegistryLocator.search_ele, doc)
        time.sleep(2)
        self.click_element(ProductContainerRegistryLocator.search_ele, doc)
        self.wait_elevisble(ProductContainerRegistryLocator.select_by_name_ele, doc)
        time.sleep(2)
        self.click_element(ProductContainerRegistryLocator.select_by_name_ele, doc)
        time.sleep(2)
        self.wait_elevisble(ProductContainerRegistryLocator.search_by_name, doc)
        self.send_keys(ProductContainerRegistryLocator.search_by_name, 'aaa', doc)
        time.sleep(3)
        self.wait_elevisble(ProductContainerRegistryLocator.sg_one_ele, doc)
        time.sleep(1)
        search_result = self.get_element(ProductContainerRegistryLocator.sg_one_ele, doc).text
        print(search_result)
        assert search_result == 'aaa'

    #安全组详情
    def security_group_detail(self):
        doc ='安全组详情'
        self.wait_elevisble(ProductContainerRegistryLocator.click_manage_rules, doc)
        self.click_element(ProductContainerRegistryLocator.click_manage_rules, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_action, doc)
        print('action+:', self.get_element(ProductContainerRegistryLocator.if_action, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_action, doc).text == 'Action'
        print('if_nic_type+:', self.get_element(ProductContainerRegistryLocator.if_nic_type, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_nic_type, doc).text == 'NIC Type'
        print('if_protocol_type+:', self.get_element(ProductContainerRegistryLocator.if_protocol_type, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_protocol_type, doc).text == 'Protocol Type'
        print('if_authorization_Type+:', self.get_element(ProductContainerRegistryLocator.if_authorization_Type, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_authorization_Type, doc).text == 'Authorization Type'
        time.sleep(5)

    #返回安全组列表
    def back_to_sglist(self):
        doc ='返回安全组列表'
        self.wait_elevisble(ProductContainerRegistryLocator.back_to_sglist, doc)
        self.click_element(ProductContainerRegistryLocator.back_to_sglist, doc)
        time.sleep(5)

    #创建inbound规则
    def create_inbound_rule(self):
        doc = '创建inbound规则'
        self.wait_elevisble(ProductContainerRegistryLocator.click_create_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_create_rule, doc)
        time.sleep(5)
        self.scroll_bar_operation(ProductContainerRegistryLocator.input_port_range)
        self.send_keys(ProductContainerRegistryLocator.input_port_range, '1/1', doc)
        time.sleep(5)
        self.scroll_bar_operation(ProductContainerRegistryLocator.input_authorization_object)
        self.send_keys(ProductContainerRegistryLocator.input_authorization_object, '1.1.1.1', doc)
        time.sleep(5)
        self.click_element(ProductContainerRegistryLocator.click_create_rule_ok, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_port_range, doc)
        print('port:', self.get_element(ProductContainerRegistryLocator.if_port_range, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_port_range, doc).text == '1/1'
        time.sleep(5)

    #删除inbound规则
    def delete_inbound_rule(self):
        doc = '删除inbound规则'
        self.wait_elevisble(ProductContainerRegistryLocator.click_delete_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_delete_rule, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_ensure_delete_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_ensure_delete_rule, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_nodate, doc)
        print('data:', self.get_element(ProductContainerRegistryLocator.if_nodate, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_nodate, doc).text == 'No data'
        time.sleep(5)

    #创建outbound规则
    def create_outbound_rule(self):
        doc = '创建outbound规则'
        self.wait_elevisble(ProductContainerRegistryLocator.click_outbound, doc)
        self.click_element(ProductContainerRegistryLocator.click_outbound, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_create_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_create_rule, doc)
        time.sleep(5)
        self.scroll_bar_operation(ProductContainerRegistryLocator.input_port_range)
        self.send_keys(ProductContainerRegistryLocator.input_port_range, '1/1', doc)
        time.sleep(5)
        self.scroll_bar_operation(ProductContainerRegistryLocator.input_authorization_object)
        self.send_keys(ProductContainerRegistryLocator.input_authorization_object, '1.1.1.1', doc)
        time.sleep(5)
        self.click_element(ProductContainerRegistryLocator.click_create_rule_ok, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_port_range, doc)
        print('port:', self.get_element(ProductContainerRegistryLocator.if_port_range, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_port_range, doc).text == '1/1'
        time.sleep(5)

    #删除outbound规则
    def delete_outbound_rule(self):
        doc = '删除outbound规则'
        self.wait_elevisble(ProductContainerRegistryLocator.click_delete_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_delete_rule, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_ensure_delete_rule, doc)
        self.click_element(ProductContainerRegistryLocator.click_ensure_delete_rule, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_nodate, doc)
        print('data:', self.get_element(ProductContainerRegistryLocator.if_nodate, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_nodate, doc).text == 'No data'
        time.sleep(5)

    # 进入vswitch页面
    def enter_vswitch_page(self):
        doc = 'vswitch页面管理控制页'
        self.click_my_resource_tab('Network')
        self.click_product_by_name('Virtual Private Clouds')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_overview, doc)
                print("if_overview++++:",self.get_element(ProductContainerRegistryLocator.if_overview, doc).text)
                if self.get_element(ProductContainerRegistryLocator.if_overview, doc).text == 'Overview':
                    break
            except:
                continue
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_vswitch, doc)
        print("click_route_tables++++:", self.get_element(ProductContainerRegistryLocator.click_vswitch, doc).text)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_vswitch, doc)
        time.sleep(5)

    #查看vswith详情
    def vswitch_info(self):
        doc = 'vswitch详情'
        self.wait_elevisble(ProductContainerRegistryLocator.click_vswitch_id, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_vswitch_id, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_basic, doc)
        print("if_vswitch_basic++++:", self.get_element(ProductContainerRegistryLocator.if_basic, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_basic, doc).text == 'Basic Information'
        print("if_vswitch_basic++++:", self.get_element(ProductContainerRegistryLocator.if_opt_records, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_opt_records, doc).text == 'Operation Records'

    #搜索vswitch
    def search_vswitch(self):
        doc = '搜索vswitch'
        self.wait_elevisble(ProductContainerRegistryLocator.input_vswitch_name, doc)
        self.send_keys(ProductContainerRegistryLocator.input_vswitch_name, 'rddsf', doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_search, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_search, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_rddsf, doc)
        print("if_rddsf++++:", self.get_element(ProductContainerRegistryLocator.if_rddsf, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_rddsf, doc).text == 'rddsf'


    #查看vpc详情
    def vpc_info(self):
        doc = 'vpc详情'
        self.wait_elevisble(ProductContainerRegistryLocator.click_left_button, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_left_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.click_vpc_id, doc)
        self.move_mouse_to_click_element(ProductContainerRegistryLocator.click_vpc_id, doc)
        time.sleep(5)
        self.wait_elevisble(ProductContainerRegistryLocator.if_basic, doc)
        print("if_vswitch_basic++++:", self.get_element(ProductContainerRegistryLocator.if_basic, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_basic, doc).text == 'Basic Information'
        print("if_vswitch_basic++++:", self.get_element(ProductContainerRegistryLocator.if_opt_records, doc).text)
        assert self.get_element(ProductContainerRegistryLocator.if_opt_records, doc).text == 'Operation Records'

    # 进入network的havip页面管理控制页
    def enter_havip_page(self):
        doc = 'acecess credential页面管理控制页'
        self.click_my_resource_tab('Network')
        self.click_product_by_name('High-availability Virtual IP Address')
        for i in range(3):
            try:
                self.wait_elevisble(ProductContainerRegistryLocator.iframe_container_registry, doc)
                self.driver.switch_to.frame(self.get_element(ProductContainerRegistryLocator.iframe_container_registry, doc))
                self.wait_elevisble(ProductContainerRegistryLocator.if_havip_id, doc)
                if self.get_element(ProductContainerRegistryLocator.if_havip_id, doc).text == 'HAVIP ID/Name':
                    break
            except:
                continue
        self.wait_elevisble(ProductContainerRegistryLocator.if_havip_id, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_havip_id, doc).text == 'HAVIP ID/Name'
        self.wait_elevisble(ProductContainerRegistryLocator.if_havip_status, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_havip_status, doc).text == 'Status'
        self.wait_elevisble(ProductContainerRegistryLocator.if_havip_ipaddress, doc)
        assert self.get_element(ProductContainerRegistryLocator.if_havip_ipaddress, doc).text == 'IP address'
        time.sleep(5)
